//Hard to Kill - Drowning (Code to survive upon air timer expiring underwater or in space at the expense of 20% energy per second)
/*addHook("ShouldDamage", function(target, inflictor, source, damage, damagetype)
	if target.player and target.player.valid then
		if target.skin ~= "annie_belnades" then --This should only work when playing as Annie
			return
		end
		
		if damagetype == DMG_DROWNED
		and player.mo.drowndelay > 0
		and player.mo.energy >= 20*FRACUNIT then
			return false --As long as the drown delay variable is above 0 and sufficient energy remains, Annie can't drown
		else
			return true
		end
	end
end, MT_PLAYER)

addHook("ShouldDamage", function(target, inflictor, source, damage, damagetype)
	if target.player and target.player.valid then
		if target.skin ~= "annie_belnades" then --This should only work when playing as Annie
			return
		end
		
		if damagetype == DMG_SPACEDROWN
		and player.mo.suffocatedelay > 0
		and player.mo.energy >= 20*FRACUNIT then
			return false --As long as the suffocate delay variable is above 0 and sufficient energy remains, Annie can't suffocate 
		else
			return true
		end
	end
end, MT_PLAYER)

addHook("PlayerThink", function(player)
	if player.mo and player.mo.valid then
	
		if player.mo.skin ~= "annie_belnades" then
			return
		end
		
		if player.mo.drowndelay == nil then --Setting up the "drown delay" variable that governs survival without air
			player.mo.drowndelay = 2*TICRATE
		end
		
		if player.mo.suffocatedelay == nil then --Setting up the "suffocate delay" variable that governs survival without air
			player.mo.suffocatedelay = 2*TICRATE
		end
		
		if player.powers[pw_underwater] ~= 1 then --Drown delay doesn't start counting down until the standard air timer runs out
			player.mo.drowndelay = 2*TICRATE
		end
		
		if player.powers[pw_spacetime] ~= 1 then -- Suffocate delay doesn't start counting down until the standard air timer runs out
			player.mo.suffocatedelay = 2*TICRATE
		end
		
		if player.mo.drowndelay <= 1*TICRATE then --If player.mo.drowndelay == TICRATE*1, that means player.powers[pw_underwater] == 1, which is when most characters would have drowned.*/
			/*code to prevent usual player death-by-drowning here then*/
/*			if (leveltime%TICRATE) then
				player.mo.drowndelay = $ - 1
			end
		end
		
		if player.mo.suffocatedelay <= 1*TICRATE then --If player.mo.suffocatedelay <= 1*TICRATE, that means player.powers[pw_spacetime] == 1, which is when most characters would have suffocated.*.
			/*code to prevent usual player death-by-suffocation here then*/
/*			if (leveltime%TICRATE) then
				player.mo.suffocatedelay = $ - 1
			end
		end
		
		if player.powers[pw_underwater] == 1
		and player.mo.drowndelay == 2*TICRATE
		and player.mo.energy >= 20*FRACUNIT then
			player.mo.drowndelay = 1*TICRATE --Delay drowning for 1 second (prevent death); start delay timer
			player.mo.energy = $ - 20*FRACUNIT --Reduce player.mo.energy by 20*FRACUNIT
			player.mo.deathdefiance = 1 --Stop energy regeneration until player gets air or dies
		end
		
		if player.powers[pw_spacetime] == 1
		and player.mo.suffocatedelay == 2*TICRATE
		and player.mo.energy >= 20*FRACUNIT then
			player.mo.suffocatedelay = 1*TICRATE --Delay suffocation for 1 second (prevent death); start delay timer
			player.mo.energy = $ - 20*FRACUNIT --Reduce p.mo.energy by 20*FRACUNIT
			player.mo.deathdefiance = 1 --Stop energy regeneration until player gets air or dies
		end*/
			
/*				If player has more than 20 energy but still has not exited water/space sector, obtained air, or obtained water protection shield (player.powers[SH_PROTECTWATER]) (pw_underwater == 1 or pw_spacetime == 1 and player.mo.energy >= 20), reduce player.mo.energy by 20*FRACUNIT and prevent death again; else, player dies (DMG_DROWNED or DMG_SPACEDROWN, PST_DEAD)
				Repeat until player.mo.energy < 20 (player dies) or pw_underwater ~= 1 or pw_spacetime ~= 1 (player lives)*/

/*		if player.mo.drowndelay == 0 then --Check if player is still drowning after 1-second delay period ends
			if player.powers[pw_underwater] ~= 1 then --if player has gotten air, end the loop
				player.mo.drowndelay = 2*TICRATE
				return
			end
		else
			if player.mo.energy >= 20*FRACUNIT then --if player has enough energy to continue surviving without air, continue the loop
				player.mo.drowndelay = 1*TICRATE --reset drown delay timer to 1 second
				player.mo.energy = $ - 20*FRACUNIT --reduce energy by 20
				player.mo.deathdefiance = 1 --energy regeneration remains paused*/
/*			else
				P_DamageMobj(player.mo, nil, nil, 1, DMG_DROWNED)*/ --If energy is insufficient to stay alive, Annie drowns and dies
/*					target = MT_PLAYER
					inflictor = nil
					source = nil
					damage = 1
					damagetype = DMG_DROWNED */ --code removed because it caused instant drowning upon game start for some reason
/*				end
			end
			
		if player.mo.suffocatedelay == 0 then --Check if player is still suffocating after 1-second delay period ends
			if player.powers[pw_spacetime] ~= 1 then --if player has gotten air, end the loop
				player.mo.suffocatedelay = 2*TICRATE
				return
			end
		else
			if player.mo.energy >= 20*FRACUNIT then --if player has enough energy to continue surviving without air, continue the loop
				player.mo.suffocatedelay = 1*TICRATE --reset suffocation delay timer to 1 second
				player.mo.energy = $ - 20*FRACUNIT --reduce energy by 20
				player.mo.deathdefiance = 1 --energy regeneration remains paused*/
/*			else
				P_DamageMobj(player.mo, nil, nil, 1, DMG_SPACEDROWN)*/ --If energy is insufficient to stay alive, Annie suffocates and dies
/*					target = MT_PLAYER
					inflictor = nil
					source = nil
					damage = 1
					damagetype = DMG_SPACEDROWN */ --code removed because it caused instant suffocation upon game start for some reason
/*				end
			end
		end
	end)*/